package guava.study.lyh.other;

import com.google.common.base.CharMatcher;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * 作者 yaohua.liu
 * 日期 2014-07-28 17:21
 * 包名 com.qunar.fresh.lyh
 * 说明 ...
 */
public class test {

    @Test
    public void testDot(){
        String str="[1234,0.1]";
        str = CharMatcher.inRange(',', ',').or(CharMatcher.inRange('.','.')).or(CharMatcher.inRange('0','9')).retainFrom(str);
        //String str = item.toString();
        if (Strings.isNullOrEmpty(str)) {
            //continue;
        }
        str=str.trim();
        // splitter.split(str);
        if(!str.contains(",")){
            // continue;
            return;
        }
        if(str.endsWith(",")){
            //continue;
            return;
        }
        String hotelId =str.substring(0,str.indexOf(","));
        System.out.println("hotelId = "+hotelId);
        String ratioStr=str.substring(str.indexOf(",")+1);
        System.out.println("ratio = "+ratioStr);
    }

    @Test
    public void testNULL(){
        Map<String, Object> score = Maps.newHashMap();
        score.put("evaluateScore","");

        float evaluateScore = 0;
        if(Objects.equal(score.get("evaluateScore"),null)){
            return;
        }
        String str = score.get("evaluateScore").toString();
        if (Strings.isNullOrEmpty(str)) {
            System.out.println("================");
        }
    }

    @Test
    public void testListAddAndRemove(){
        List<String> test = new ArrayList();
        test.add("http://userimg.qunar.com/imgs/201102/23/NNNh-PNydYmL_3Y9N180s.jpg");
        test.add("http://userimg.qunar.com/imgs/201102/23/aa180.jpg");
        test.add("test");
        test.add("from");
        test.add("to");
        for(String line:test){
            if(line.equals("from")){
                test.remove(line);
            }
        }
        for(String line:test){
            System.out.println(line);
        }
    }

    @Test
    public void testReplace() {
        List<String> test = new ArrayList();
        test.add("http://userimg.qunar.com/imgs/201102/23/NNNh-PNydYmL_3Y9N180s.jpg");
        test.add("http://userimg.qunar.com/imgs/201102/23/aa180.jpg");
        test.add("");
        test.add("  ");
        test.add(null);
        for (String line : test) {
            System.out.println(Strings.isNullOrEmpty(line) + ":" + line);
            //            Preconditions.checkNotNull(line, "参数不能为空");
            Preconditions.checkState(!Strings.isNullOrEmpty(line), "参数不能为空");
            /*if(Strings.isNullOrEmpty(line)){
                throw new IllegalArgumentException("参数不能为空");
            }*/
            /*if (line.endsWith("s.jpg")) {
                System.out.println("原来：" + line);
                line = line.replace("s.jpg", ".jpg");
                System.out.println("现在：" + line);
            }*/
        }
    }

    @Test
    public void testT() {
        new MyTest<String>().print("aa");
    }

    class MyTest<T> {
        String name;
        int id;

        public void print(T result) {

        }
    }

    @Test
    public void testException(){
       /* try{
            throw new OutOfMemoryError("===");
        }catch (Exception e){
            System.out.println("xxxx"+e.getMessage());
        }catch (Throwable t){
            System.out.println("tt" + t.getMessage());
        }*/

        try{
            throw new IllegalArgumentException("xx");
        }catch (Exception e){
            System.out.println("xxxx"+e.getMessage());
        }finally {
            throw new IllegalArgumentException("finally xx");
            /*try{
                throw new IllegalArgumentException("finally xx");
            }catch (Exception e){
                System.out.println("finally xxxx"+e.getMessage());
            }*/
        }
    }

    @Test
    public void testTime(){
        Calendar cal = Calendar.getInstance();
        int hour=cal.get(Calendar.HOUR);//小时
        int minute=cal.get(Calendar.MINUTE);//分
        System.out.println(hour+","+minute);

        String c = "2015-10-17";
        System.out.println(c.substring(0,10));
    }
}